import time

class Timeout():

    def __init__(self, duration_ms):
        self.__end_time = time.time() + (duration_ms / 1000.0);

    def has_timed_out(self):
        return self.time_remaining() <= 0

    def wait_on(self, lock):
        wait_time = self.time_remaining()
        if (wait_time > 0):
            lock.wait(wait_time)

    def time_remaining(self):
        return self.end_time - time.time()

    @property
    def end_time(self):
        return self.__end_time


